define(['../../../../js/lib/other/sweet-alert'],function() {
    return ['$scope','$location', '$interval','$timeout','bizProxy', function($scope,$location,$interval,$timeout,bizProxy) {
    	$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','case_src_lib'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	if(_YHC_isWEIXIN.isWeiXin()){
    		$scope.$emit('flag-tag','75'); 	//显示底部文字
    	}else{
    		$scope.$emit('flag-tag','2'); 	//显示底部文字
    	}

    	
    	if(resultData.caseDetailData != ""){
    		if(transData.userType === "1"&&resultData.caseDetailData.status == 'B'){
    			$scope.isActive = true;
    			$scope.showApply = true;
    		}else{
    			$scope.isActive = false;
    			$scope.showApply = false;
    		}
    		$scope.caseDetailData = resultData.caseDetailData;
    		if(resultData.caseDetailData.isFavor==="Y"){
    			if(_YHC_isWEIXIN.isWeiXin()){
					$scope.$emit('flag-tag','75-1'); 	//显示底部文字
				}else{
                	$scope.$emit('flag-tag','2-1');
				}
			}else {
                if(_YHC_isWEIXIN.isWeiXin()){
		    		$scope.$emit('flag-tag','75'); 	//显示底部文字
		    	}else{
		    		$scope.$emit('flag-tag','2'); 	//显示底部文字
		    	}
			}
    	}
    	
    	$scope.viewpointAdv = "",$scope.communicationAdv = "",$scope.understandAdv = '',$scope.anotherAdv = "";
    	
    	//点击申请承接此案件
    	$scope.isSlide_up = false;
    	$scope.applyCase = function(){
    		if(transData.mobileNo != "" && transData.sessionId != ""){
    			if(transData.userType === "1"){
    				if(resultData.loginUserData.userName != "" && resultData.loginUserData.userName != null){
    					$scope.isSlide_up = true;
        				$scope.userName = resultData.loginUserData;
    				}else{//未完善资料用户不可发布
        				FIREFLY("请先去'我的'里面完善个人信息", "","",function(){});
        			}
    			}else{
    				FIREFLY("只有律师用户才能申请此案件!", "","",function(){});
        			return;
    			}
    		}else{
    			transData.gotoUrl = "/caseProfile";
    			$scope.$emit("goNext","/login");
    		}
    		
    	}
    	//点击关闭申请承接此案
    	$scope.closeApplyCase = function(){
    		$scope.isSlide_up = false;
    	}
    	
    	//提交申请按钮
    	$scope.subApplyfor = function(){
    		caseApplyfor();
    	}
    	
    	//监听收藏点击事件
    	$scope.$on('collectionEvent', function(event,data){
    		if(data){
                favorManage();
    		}
        });
    	
    	//监听分享事件
    	$scope.$on('shareEvent', function(event,data){
    		if(data){
//    			alert("caseId="+resultData.caseDetailData.caseId);
//    			alert('开始分享')
    			share.share($scope.caseDetailData.caseMemo?$scope.caseDetailData.caseMemo:'',$scope.caseDetailData.creditorName+' VS '+$scope.caseDetailData.debtorName,$scope.caseDetailData.caseId+"",null,null);
    		}
        });
    	
    	//收藏案件
    	function favorManage(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;

        	if(resultData.caseDetailData.isFavor==="Y"){
                bizInfo.operation = "del";
                bizInfo.ids = resultData.caseDetailData.caseId;
			}else {
                bizInfo.operation = "add";
                bizInfo.favorId = resultData.caseDetailData.caseId;
			}
        	bizInfo.favorType = 'case';
        	console.log(bizInfo)
        	bizProxy.queryProxyBizData("favorManage",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
						console.log(tempData)
		        		$scope.$emit("showCollect",true);
						$timeout(function(){
							$scope.$emit("showCollect",false);
						},1500);
                        if(resultData.caseDetailData.isFavor==="Y"){
                            if(_YHC_isWEIXIN.isWeiXin()){
					    		$scope.$emit('flag-tag','75'); 	//显示底部文字
					    	}else{
					    		$scope.$emit('flag-tag','2'); 	//显示底部文字
					    	}
                            resultData.caseDetailData.isFavor="N"
                            $scope.$emit("promptAlertMsg","取消收藏成功");
                        }else {
                            $scope.$emit("promptAlertMsg","已收藏成功");
                            resultData.caseDetailData.isFavor="Y";
                            if(_YHC_isWEIXIN.isWeiXin()){
								$scope.$emit('flag-tag','75-1'); 	//显示底部文字
							}else{
			                	$scope.$emit('flag-tag','2-1');
							}
                        }
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginResultData = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
				        		$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},1500);
							}
		    			}else{
		    				$scope.$emit("promptAlertMsg","收藏连接超时");
			        		$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
							},1500);
		    			}
		    		});
    	}
    	
    	//提交申请案件到代理
    	function caseApplyfor(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.caseId = resultData.caseDetailData.caseId;
        	bizInfo.memoContent = {
        			"viewpointAdv": $scope.viewpointAdv,
        			"communicationAdv": $scope.communicationAdv,
        			"understandAdv": $scope.understandAdv,
        			"anotherAdv": $scope.anotherAdv
        	};
    		$scope.$emit("loadingChange",true);
    		console.log(bizInfo)
    		bizProxy.queryProxyBizData("submitCaseOrder",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
                        console.log(tempData)
		    			$scope.$emit("loadingChange",false);
						$timeout(function(){
							$scope.$emit("goNext","/sucApplyfpr")
						},0);
		    		},function(data){
    					console.log(data)
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							resultData.loginResultData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								FIREFLY("", data.errorMsg,"",function(){
									$timeout(function(){
										$scope.$emit("loadingChange",false);
									},0);
								});
							}
		    			}else{
			    			FIREFLY("连接超时", "","",function(){
			    				$timeout(function(){
			    					$scope.$emit("loadingChange",false);
		    					},0);
			    			});
		    			}
		    		});
    	}
    	
    	
        $scope.$apply();
    }];
});